const href = self.location.href.split('=')[1];
// console.log(href.split('=')[1])
console.log($().jquery); // => '3.6.0'
var $jq = jQuery.noConflict(true);
// 现在window.$和window.jQuery被恢复成1.5版本:
console.log($().jquery); // => '1.5.0'
console.log($jq().jquery);


const loginId = $.cookie('ID');
const loginToken = $.cookie('Token');

// console.log(loginId, loginToken);

// function isLogin() {
//     if (loginId !== undefined && loginToken !== undefined) {
//         return 0;
//     }
//     else{
//         setTimeout(()=>{
//             location.href= 'login.html';
//         },300);
//     }
// }
//
// isLogin();


$('#index').on('click', () => {
    location.href = 'index.html';
})

const Detail = localStorage.getItem('Detail' + href);
let Msg = JSON.parse(Detail);
if (Msg == '' || Msg == null || Msg == undefined) {
    console.log('Msg is Null ! ');
    // Msg = {
    //     src: '//image8.wbiao.co/shop/42fd45fb652e4f2a8482d228c4513c6c.jpg',
    // };
    setTimeout(()=>{
        location.href='GoodList.html';
    },200)
} else {
    console.log(Msg);
    // console.log(JSON.parse(Detail));
    // console.log(Msg);
    if (href === '' || href === undefined) {
        setTimeout(() => {
            location.href = 'GoodList.html';
        }, 300)
    }
}
$('#jqzoomDiv a').attr('href', Msg.src);
$('#jqzoomDiv img').attr('src', Msg.src);

// $('#bigImg').attr('src', Msg.src);
// let ress = $('#jqzoomDiv img').eq(0).attr('src', Msg.src);
// console.log(ress)

axios.get("http://localhost:8009/?id=" + href).then(res => {
    console.log(res.data)
    $('body').eq(0).append(res.data.detail);
    $('.W_pt_head').remove();
    $('.W_pt_top').remove();
    $('.W_top_banner').remove();
    $('.pt-shop_nav').remove();
    $('.pt-shop_sign').remove();
    $('.W_detail_Bread').remove();
    $('.detail_upper').remove();
    $('#upper').remove();
    // $('.lower_left').remove();
})


//
// $jq(function () {
//     $jq('.jqzoom').jqzoom({
//         //（默认值）standard / reverse,原图用半透明图层遮盖
//         zoomType: 'standard',
//         //是否在原图上显示镜头
//         lens: false,
//         // 预先加载大图片
//         preloadImages: true,
//         //放大镜是否总是显示存在
//         alwaysOn: false,
//         //放大窗口的尺寸
//         zoomWidth: 600,
//         zoomHeight: 800,
//         //放大窗口相对于原图的偏移量、位置
//         xOffset: 0,
//         yOffset: 0,
//         position: 'left',
//         //默认值：true，是否显示加载提示Loading zoom
//         showPreload: true,
//         //默认 Loading zoom，自定义加载提示文本
//         preloadText: '加载中……'
//         //imageOpacity 默认值 0.2 透明度
//         //title 是否在放大窗口中显示标题，值可以为a标记的title值，若无，则为原图的title值
//     });
// });
$jq(document).ready(function () {
    $jq('.jqzoom').jqzoom({
        zoomType: 'innerzoom',
        preloadImages: true,
        alwaysOn: false,
        zoomWidth: 600,
// zoomHeight: 600,
    });
});


// 渲染数据
$('.li-1').html('<p>' + Msg.title + '</p>');
console.log(Msg.price.split('¥')[1])
if ((Msg.price.split('¥')[1] - 0) > 10000) {
    $('.li-2 .p1 span').eq(1).text("¥" + ((Msg.price.split('¥')[1] - 0) + 10000));
    $('.li-2 .p1 span').eq(2).text('到手价' + Msg.price);
    $('.li-2 .p2 span').eq(0).text(Math.round((Msg.price.split('¥')[1] - 0) / 24) + 'X' + ' 24期');
} else {
    $('.li-2 .p1 span').eq(1).text("¥" + ((Msg.price.split('¥')[1] - 0) + 500));
    $('.li-2 .p1 span').eq(2).text('到手价' + Msg.price);
    $('.li-2 .p2 span').eq(0).text((Msg.price.split('¥')[1] - 0) / 24 + 'X' + ' 24期');
}


$('#join').on('click', () => {
    console.log('join');
    const ID = $.cookie('ID');
    const TOKEN = $.cookie('Token');
    const key = localStorage.getItem('Detail' + href);
    const res = JSON.parse(key);
    // console.log(key,res);

    if (loginId === undefined && loginToken === undefined) {
        setTimeout(() => {
            location.href = 'login.html';
        }, 300);
        return -1;
    }
    const card = JSON.stringify(res);
    // if ($cookie("ID") != '')
    // const ID = $.cookie('ID');
    // console.log(ID)
    // const TOKEN = $.cookie('TOKEN');
    // console.log(TOKEN)
    // console.log(1);
    // console.log(ID,TOKEN);

    console.log(1);
    alert('已添加到购物车！');
    let goShopData = localStorage.getItem('Detail' + href);

    // localStorage.setItem('Detail'+ href, goShopData);
    localStorage.setItem(ID + "&" + href, goShopData);
    // localStorage.removeItem('Detail' + href);
})

$('#buy').on('click', () => {
    console.log(1);
    const ID = $.cookie('ID');
    const TOKEN = $.cookie('Token');
    if (TOKEN === '' || TOKEN === undefined) {
        setTimeout(() => {
            location.href = 'login.html';
        }, 1000)
    } else {
        let goShopData = localStorage.getItem('Detail' + href);
        localStorage.setItem(ID + "&" + href, goShopData);
        location.href = 'http://localhost:8080/dist/ShopCard.html?id=' + href;
    }
})


$('#floor li').on('click', 'img',  function() {
    // console.log(1);
    // console.log(this);
    // console.log($(this));

    if($('#floor li img')[0] === this){
        location.href = 'index.html';
    }
    if($('#floor li img')[1] === this){
        location.href = 'shopCard.html';
    }
    if($('#floor li img')[2] === this){
        location.href = 'login.html';
    }
    if($('#floor li img')[3] === this){
        console.log(1)
        $('body, html').animate({
            'scrollTop': 0,
        },500)
    }
})
